package com.lanyam.travel.base.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanyam.travel.base.entity.TravelOrder;
import com.lanyam.travel.base.entity.vo.FormReport;
import com.lanyam.travel.base.entity.vo.TravelOrderVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author rosson
 * @since 2020-01-27
 */
@Mapper
public interface TravelOrderMapper extends BaseMapper<TravelOrder> {

    /**
     * 分页查询
     */
    Page<TravelOrderVo> getPage(@Param("page") IPage<TravelOrderVo> page, @Param("map") Map<String, Object> map);

    /**
     * 删除数据
     */
    void delById(String id);

    /**
     * 分页查询
     */
    List<TravelOrderVo> getList(@Param("map") Map<String, Object> map);

//  	@Select("SELECT DATE_FORMAT(order_date, '%Y/%m/%d') AS strKey,COUNT(1) AS count \n" + 
//  			"FROM travel_order \n" + 
//  			"WHERE  order_date >= DATE_FORMAT(#{startDate}, '%Y/%m/%d') AND order_date <= DATE_FORMAT(#{endDate}, '%Y/%m/%d') AND goods_type = #{goodsType}\n" + 
//  			"GROUP BY DATE_FORMAT(order_date, '%Y/%m/%d')\n" + 
//  			"ORDER BY DATE_FORMAT(order_date, '/%Y/%m/%d')")
    /**
     * 按天统计订单数
     * @param map
     * @return
     */
  	List<FormReport> getOrderCountByDays(@Param("map") Map<String,String> map);
//  	@Select("SELECT COUNT(1) AS count FROM travel_order WHERE DATE_FORMAT(order_date,'%Y/%m')=#{month} AND STATUS = #{status}")
	/**
	 * 按订单状态统计订单数
	 * @param map
	 * @return
	 */
  	Integer getorderCountByStatus(@Param("map") Map<String,String> map);

    /**
     * 获取未计算的订单列表
     * @return
     */
  	List<TravelOrder> getNotCalcOrderList(@Param("date") Date date);

    /**
     * 更新订单状态
     */
  	void updateCalcCashStatus(@Param("date") Date date);
  	/**
  	 * 查询当月的订单金额
  	 * @param map
  	 * @return
  	 */
	Integer getOrderAmountInMonth(@Param("map") Map<String,String> map);
	/**
	 * 查询所有的订单总数
	 * @param map
	 * @return
	 */
	Integer getAllOrderCount(@Param("map") Map<String,String> map);
	/**
	 * 查询全部订单的总金额
	 * @param map
	 * @return
	 */
	Integer getAllOrderAmount(@Param("map") Map<String,String> map);
	/**
	  * 	获取订待审核订单单分页信息
	  * @param reqMap reqMap中的key:goodsId线路/景点/酒店id;userId 下单人id;status 0未付款，1已付款/未出行，3已出行，4退款;
	  * @return
	  */
	Page<TravelOrderVo> getExamOrderPage(Page<TravelOrderVo> page,  @Param("map") Map<String, Object> map);
	/**
	 * 搜索待验票的订单
	 * @param userId:登陆的用户id，必填项，checkCode:验票码或订单号，startDate:下单时间搜索的下限值，endDate:下单时间搜索的上限值
	 * @return
	 */
	List<TravelOrderVo> searchCheckOrder( @Param("map") Map<String, Object> map);
	 /**
	  * 财务管理获取订单分页数据
	  * @param reqMap
	  * @return
	  */
	Page<TravelOrderVo> queryFinanceOrderByPage(Page<TravelOrderVo> page, @Param("map") Map<String, Object> map);

	/**
	 * 查看普通会员的消费金额
	 * @param userId
	 * @return
	 */
	@Select("select sum(pay_amount) as totalCost from travel_order where order_userid = #{userId}")
	Double getCostAmountByUserId(String userId);
}
